
import store from "@/store";

function hasPermiInstall(app) {
    app.directive('hasPermi', (el, { value }) => {
        const allPermissions = '*:*:*';
        const { permissions } = store.state;
        if (!(value && value instanceof Array && value.length)) throw new Error('请设置操作权限标签值');
        const hasPermissions = permissions.some((permi) => allPermissions === permi || value.includes(permi));
        if (!hasPermissions && el.parentNode) el.parentNode.removeChild(el);
    });
}

export default hasPermiInstall;
